 /**
This file is part of Studentport.

    Studentport is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Studentport is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Studentport.  If not, see <http://www.gnu.org/licenses/>.

**/
package com.groupalpha.studentport;

import com.httpclasses.perfectConnect;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;

/**
 * 
 * Will present the user with an webview loaded with the htmlstring from perfectConnect.getresult() method.
 * if error occur an error toast message is presented.
 * @author GroupAlpha 
 *
 */
public class ResultatEN extends Activity{
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.resultat);
        final Button logoffButton = (Button) findViewById(R.id.button2);
        logoffButton.setBackgroundResource(R.drawable.logoff_button_en);
        final WebView web = (WebView) findViewById(R.id.webView1);
        
 
        
        final ProgressDialog dialog = new ProgressDialog(ResultatEN.this);
        final Toast toast = Toast.makeText(ResultatEN.this, "Error", Toast.LENGTH_SHORT);
   	 	
        web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        web.setVerticalScrollBarEnabled(false);
        web.getSettings().setBuiltInZoomControls(true);
        web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        dialog.setTitle("Loading Listing of results");
   	 	dialog.setMessage("Wait...");
   	 	dialog.setCancelable(false);
   	 	dialog.show();
   	 	new Thread(){
   	 		public void run(){
   	 		try {
   	        	final String s = (perfectConnect.getInstance().getresultEN());
   	        	
   	        	ResultatEN.this.runOnUiThread(new Runnable(){public void run(){web.loadData(s, "text/html","ISO-8859-1");
   	        	dialog.dismiss();
   	        	}});
   	        	
   			} catch (Exception e) {
   				// TODO Auto-generated catch block
   				toast.show();
   				dialog.dismiss();
   			}
   	 			
   	 		}
   	 	}.start();
   	 	
   	 logoffButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         	Intent intent = new Intent(ResultatEN.this, StudentportActivity.class); 
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Removes other Activities from stack 
				startActivity(intent);
         }
         });
        
		
    }
        
    
}